﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NumberParser
{
    public class Line
    {
        List<Square> squares = new List<Square>(5);

        public Line()
        {

        }

        public Line(List<Square> squares)
        {
            this.squares = squares;
        }

        public bool AddSquare(Square square)
        {
            if (squares.Capacity > squares.Count)
            {
                squares.Add(square);
                return true;
            }
            return false;
        }

        public List<Square> Squares
        { get { return this.squares; } }

        public override string ToString()
        {
            string result = string.Empty;
            foreach (var item in squares)
            {
                result += item.ToString();
            }
            return result;
        }

        public bool Matches(Line lineToMatch)
        {
            for (int i = 0; i < squares.Count; i++)
            {
                if (!squares[i].Matches(lineToMatch.Squares[i]))
                    return false;
            }
            return true;
        }

        public static Line TransformLine(string line)
        {
            var result = new Line();
            foreach (var item in line)
            {
                Square sq;
                if (item == ' ')
                    sq = new Square(' ', false);
                else
                    sq = new Square(item, true);
                result.AddSquare(sq);
            }
            return result;
        }

        public bool IsValid
        {
            get
            {
                foreach (var item in squares)
                {
                    if (item.Filled)
                        return true;
                }
                return false;
            }
        }
    }
}
